<?php 

class AdminModel extends Model{
	public $table='blog_admin';
	public function userLogin()
	{
		if (empty($_POST['username'])) {
			$this->error='账号不能为空';
			return false;
		}
		if (empty($_POST['password'])) {
			$this->error='密码不能为空';
			return false;
		}
		$user=$this->where("username='{$_POST['username']}'")->find();
		if ($user['username']!=$_POST['username']) {
			$this->error='账号错误';
			return false;
		}
		if ($user['password']!=md5($_POST['password'])) {
			$this->error='密码错误';
			return false;
		}
		$_SESSION['aid']=$user['aid'];
		$_SESSION['password']=$user['username'];
		return true;
	}

	//修改密码
	public function editLogin($data)
	{
		$oldUser=$this->find();
		if (empty($data['password'])) {
			$this->error="密码不能为空";
			return false;
		}
		if (md5($data['oldPassword'])!=$oldUser['password']) {
			$this->error="旧密码输入错误";
			return false;
		}
		$data['password']=md5($data['password']);
		unset($data['oldPassword']);
		$_SESSION['aid']=$oldUser['aid'];//id号唯一
		$_SESSION['username']=$data['password'];
		return $this->where(" aid={$oldUser['aid']}")->update($data);
	}
	//获取管理员信息
	public function userInfor()
	{
		return $user=$this->find();
	}

	//修改个人信息
	public function editUserinfor($data)
	{
		if (empty($data['username'])) {
			$this->error="用户名不能为空";
			return false;
		}
		if (empty($data['tel'])) {
			$this->error="手机号不能为空";
			return false;
		}
		return $this->where(" username='{$_GET['username']}'")->update($data);
	}
}


 ?>